﻿using System.IO;
using System.IO.Compression;

namespace Report.Service
{
    public class CompressHelper
    {
        public static byte[] GzipDeCompress(byte[] data)
        {
            using (var ms = new MemoryStream(data))
            {
                var gs = new GZipStream(ms, CompressionMode.Decompress);

                var decompressedMs = new MemoryStream();

                var buffer = new byte[1024];

                int len = 0;

                while ((len = gs.Read(buffer, 0, buffer.Length)) > 0)
                {
                    decompressedMs.Write(buffer, 0, len);
                }

                return decompressedMs.ToArray();
            }
        }

        public static byte[] DeflateDeCompress(byte[] data)
        {
            using (var ms = new MemoryStream(data))
            {
                var gs = new DeflateStream(ms, CompressionMode.Decompress);

                var decompressedMs = new MemoryStream();

                var buffer = new byte[1024];

                int len = 0;
                while ((len = gs.Read(buffer, 0, buffer.Length)) > 0)
                {
                    decompressedMs.Write(buffer, 0, len);
                }

                return decompressedMs.ToArray();
            }
        }
    }
}